#ifndef HEAD_H
#define HEAD_H

#include <QDebug>
#include <QTimer>
#include <QMap>
#include <QFile>
#include <QDir>


#include <QThread>

#define _THIS_NET_MAC_ 12


#pragma pack(push, 1)  // 开始1字节对齐

typedef struct SaveDataHead
{
    unsigned char _head[4] = {0x5A, 0xA5, 0x0D, 0x0A};
    unsigned int _size = 0;     // 总数据量大小 （协议头 + 数据 + 协议尾）

}SaveDataHead;


typedef struct SaveDataTail
{
    unsigned char _tail[4] = {0x0A, 0x0D, 0xA5, 0x5A};
}SaveDataTail;


#pragma pack(pop)   // 恢复默认对齐

/*
void SaveFileThread::working(const QString ip, const quint16 port, const QByteArray arr)
{
    //qDebug() << "ip:" << ip;
    //if(ip != m_targetIP || port != m_port) return;
    if(port != m_port) return;

    if(m_splitWayIndex == 0) {
        if(m_currFileSize > m_splitWayValueBytes)  // 文件大小控制在 m_maxFileSize
        {
            m_file.close();

            QString fileName = QString("./data/%1/%2_%3.dat").arg(m_desc).arg(m_desc).arg(QDateTime::currentDateTime().toString("yyyy_MM_dd_hh_mm_ss"));

            m_file.setFileName(fileName);
            m_file.open(QIODevice::WriteOnly);
            m_currFileSize = 0;

            qDebug() << "create file : " << fileName;


    #if _IS_PROTOCOL_

            SaveDataHead dh;
            dh._size = sizeof(SaveDataHead) + sizeof(SaveDataTail) + arr.size();
            SaveDataTail dt;

            QByteArray arr_t(1,0);
            arr_t.resize(dh._size);

            memcpy(arr_t.data(), &dh, sizeof dh);
            memcpy(arr_t.data() + sizeof dh, arr.data(), arr.size());
            memcpy(arr_t.data() + sizeof dh + arr.size(), &dt, sizeof dt);

            if(m_file.write(arr_t) == -1)
            {
                qDebug() << "写入文件失败:" << m_file.errorString();
                m_file.close();
                return;
            }

            m_currFileSize += arr_t.size();

    #else
            if(m_file.write(arr) == -1)
            {
                qDebug() << "写入文件失败:" << m_file.errorString();
                m_file.close();
                return;
            }

            m_currFileSize += arr.size();
    #endif

        }
        else
        {

    #if _IS_PROTOCOL_

            SaveDataHead dh;
            dh._size = sizeof(SaveDataHead) + sizeof(SaveDataTail) + arr.size();
            SaveDataTail dt;

            QByteArray arr_t(1,0);
            arr_t.resize(dh._size);

            memcpy(arr_t.data(), &dh, sizeof dh);
            memcpy(arr_t.data() + sizeof dh, arr.data(), arr.size());
            memcpy(arr_t.data() + sizeof dh + arr.size(), &dt, sizeof dt);

            if(m_file.write(arr_t) == -1)
            {
                qDebug() << "写入文件失败:" << m_file.errorString();
                m_file.close();
                return;
            }

            m_currFileSize += arr_t.size();

    #else
            if(m_file.write(arr) == -1)
            {
                qDebug() << "写入文件失败:" << m_file.errorString();
                m_file.close();
                return;
            }

            m_currFileSize += arr.size();
    #endif

        }

    }

}*/


#endif // HEAD_H
